﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FUSE
{
    public class Blackhole : FUSE.MassedComponent
    {
        private Rectangle blackholeSource = new Rectangle();
        private Texture2D spriteMap;
        private double lastIteration = 0;
        private int iterationLength = 75;

        public Blackhole() :base()
        {
            throw new NotImplementedException();
        }
           

        public Blackhole(int mass) 
            :base(11)
        {
        }

        public override void Initialize()
        {
            base.Initialize();
            this.lastIteration = 0;
        }


        public override void LoadContent(Texture2D spriteMap)
        {

            this.spriteMap = spriteMap;
            Texture2D sourceTexture = new Texture2D(spriteMap.GraphicsDevice, 75, 75);
            blackholeSource = new Rectangle(0, 0, 75, 75);

            base.LoadContent(sourceTexture);
        }

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {

            double currentTime = gameTime.TotalGameTime.TotalMilliseconds;
            if ((currentTime - lastIteration) > 100)
            {
                if (((blackholeSource.X + iterationLength) >= spriteMap.Width) || ((blackholeSource.X + iterationLength) < 0))
                {
                    //iterationLength *= -1;                    
                    blackholeSource.X = -1 * iterationLength;
                }

                blackholeSource.X += iterationLength;

                lastIteration = currentTime;
            }

            spriteBatch.Draw(this.spriteMap, base.RenderPosition, blackholeSource, Color.White);
        }
    }
}
